package com.mincko.minckotest.server;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobInfo;
import com.google.appengine.api.blobstore.BlobInfoFactory;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class Serve extends HttpServlet {
    private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException {
        BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
        
        Iterator<BlobInfo> iterator = null;
        
        iterator = new BlobInfoFactory().queryBlobInfos();
        while ( iterator.hasNext())
        {
        	BlobInfo bi = iterator.next();
        	//System.out.println( bi.getFilename() +":" + bi.getBlobKey());
        }
        //Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        //Set set = blobs.keySet();
        
        blobstoreService.serve(blobKey, res);
    }
}
